package com.spark.gaea.data.mybatis.backend;

import com.google.common.base.Strings;
import com.spark.gaea.data.mybatis.Dao;
import com.spark.gaea.data.mybatis.DataPermissionsBacked;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

public class MysqlDataPermission implements DataPermissionsBacked {
	@Autowired
	private Dao dao;

	@Override
	public Set<Map<String, String>> getSqlParameterList(final String userId, final String sqlId) {
		if (Strings.isNullOrEmpty(userId) || Strings.isNullOrEmpty(sqlId)) {
			return null;
		}
		final HashMap params = new HashMap();
		params.put("userId", userId);
		params.put("sqlId", sqlId);
		final List<Map<String, String>> list = this.dao.getList("sqlRoleParameter.query.", "getSqlParameter", params);
		final Set<Map<String, String>> sqlpers = new HashSet<Map<String, String>>();
		for (final Map sqlper : list) {
			sqlpers.add(sqlper);
		}
		return sqlpers;
	}
}
